/*
 * Copyright (c) 2019 DawnFramework. All Rights Reserved.
 * Licensed under the MIT (LICENSE) license.
 */

package org.dawn.common.apiclient;

import lombok.Getter;
import org.dawn.common.apiclient.auth.Authentication;
import org.dawn.common.apiclient.model.Pair;
import org.dawn.common.core.utils.Strings;

import java.util.List;
import java.util.Map;

/**
 * @author Willard Hu on 2019-04-23.
 */
@Getter
public class RequestContext {
    /** The sub-path of the HTTP URL */
    private String path;
    /** The request method */
    private HttpMethods method;
    /** The query parameters */
    private List<Pair> queryParams;
    /** The collection query parameters */
    private List<Pair> collectionQueryParams;
    /** The request body object */
    private Object body;
    /** The header parameters */
    private Map<String, String> headerParams;
    /** The form parameters */
    private Map<String, Object> formParams;
    /** The authentications to apply */
    private List<String> authNames;
    /** The real-time authentications to apply */
    private List<Authentication> realTimeAuthentications;
    /** Progress request listener */
    private ProgressRequestBody.ProgressRequestListener progressRequestListener;

    public static RequestContext newRequestContext(String path, HttpMethods method) {
        assert Strings.isNotBlank(path) : "Path can not be blank";
        assert method != null : "Http method can not be null";

        RequestContext builder = new RequestContext();
        builder.path = path;
        builder.method = method;
        return builder;
    }

    public RequestContext queryParams(List<Pair> queryParams) {
        this.queryParams = queryParams;
        return this;
    }

    public RequestContext collectionQueryParams(List<Pair> collectionQueryParams) {
        this.collectionQueryParams = collectionQueryParams;
        return this;
    }

    public RequestContext body(Object body) {
        this.body = body;
        return this;
    }

    public RequestContext headerParams(Map<String, String> headerParams) {
        this.headerParams = headerParams;
        return this;
    }

    public RequestContext formParams(Map<String, Object> formParams) {
        this.formParams = formParams;
        return this;
    }

    public RequestContext authNames(List<String> authNames) {
        this.authNames = authNames;
        return this;
    }

    public RequestContext realTimeAuthentications(List<Authentication> realTimeAuthentications) {
        this.realTimeAuthentications = realTimeAuthentications;
        return this;
    }

    public RequestContext progressRequestListener(ProgressRequestBody.ProgressRequestListener progressRequestListener) {
        this.progressRequestListener = progressRequestListener;
        return this;
    }
}
